var reviewRecordDetalisData = [];
var exportFlag = undefined;

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	createTableHead("detailsRecordThead", reviewRecordDetalisTable);
	search();
});

function search(){
	$('#ID').val($("#detailID", parent.document).val());
	var IDList = $('#ID').val().split(",");
	$('#lineName').val(IDList[5]);
	$("#detailID", parent.document).val("");
	$ajax('searchLineRecordDetail', {
		SubBranchCompanyID : IDList[0],
		TeamID : IDList[1],
		LineID : IDList[2],
		StartChargingDate : IDList[3],
		EndChargingDate : IDList[4]
		}, searchReviewRecord);
}

function searchReviewRecord(data){
	reviewRecordDetalisData = data && data.lineRecordDetailList || [];
	createTableBody("detailsRecordTbody", reviewRecordDetalisTable, reviewRecordDetalisData, true, true);
}

function goback() {
	$("#iframeDetalis", parent.document).hide();
}
function sure(){
	showMessge("导出中...");
	$ajaxCommon('exportChargingRecord?checkFlag=', exportFileResult);
}
function exportFileResult(data){
	var result = data && data.result;
	if (result == "Success") {
		showLoading();
		var lineName = $('#lineName').val();
		downloadFile('exportChargingRecord?checkFlag=OK&lineName=' + lineName);
		showMessge("导出成功,记录审核文件正在生成！");
		setTimeout(hideLoading, 2000);
	} else if (result == "JsonError") {
		showMessge("导出失败，导出的JSON模板错误 或 不存在！");
	} else if (result == "NotFound") {
		showMessge("导出失败，没有数据可导出！");
	} else {
		showMessge("导出失败，请重新导出 或 联系管理员！");
	}
}
function showMessge(message, model, callback) {
	model = model == undefined ? "model1" : model;
	$('#message', parent.parent.document).html(message || '提示消息未设置！');
	$('#model1', parent.parent.document).hide();
	$('#model2', parent.parent.document).hide();
	$('#model3', parent.parent.document).hide();
	$("#" + model, parent.parent.document).show();
	$('#close1', parent.parent.document).hide();
	$('#close3', parent.parent.document).hide();
	if (model == "model3") {
		$('#close3', parent.parent.document).show();
	} else {
		$('#close1', parent.parent.document).show();
	}
	if ($('.modal-backdrop.fade.in').length > 0) {
		setTimeout(setMessageModal, 500);
	} else {
		setMessageModal();
	}
	
	if (typeof callback === 'function') {
		$('#myMessageModal', parent.parent.document).on('shown.bs.modal', function (e) {
			callback();
		});
	}
}
function setMessageModal() {
	$('#myMessageModal', parent.parent.document).modal('show');
}
function hideMessge() {
	$('#myMessageModal', parent.parent.document).modal('hide');
}
function showLoading() {
	$('#loadingModal', parent.parent.document).modal('show');
}

function hideLoading() {
	$('#loadingModal', parent.parent.document).modal('hide');
}